package com.study.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @Description TODO
 * bean实例后置处理器之间执行的
 * @Author v_yangliu
 * @Date 2022/1/11 14:49
 * @Version 1.0
 **/
@Slf4j
public class PostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("initBeanFactoryPostProcessorTest".equals(beanName)) {
            log.info("后置处理器处理bean=【" + beanName + "】开始");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if ("initBeanFactoryPostProcessorTest".equals(beanName)) {
            log.info("后置处理器处理bean=【" + beanName + "】结束");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return bean;
    }
}
